{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.07 0.06 0.25]\n"
     ]
    }
   ],
   "source": [
    "a1 = np.array([0.7, 0.2, 0.5])\n",
    "a2 = np.array([0.1, 0.3, 0.5])\n",
    "\n",
    "print(a1 * a2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.03512363, -0.06028172, -0.07396711,  0.07950596,  0.05796083])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "min = -0.1\n",
    "max = 0.1\n",
    "\n",
    "a3 = min + (max - min) * np.random.rand(5)\n",
    "a3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0.03512363 -0.06028172 -0.07396711  0.07950596  0.05796083]\n"
     ]
    }
   ],
   "source": [
    "print(a3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0.03512363 -0.04       -0.04        0.04        0.04      ]\n"
     ]
    }
   ],
   "source": [
    "np.clip(a3, a_min=-0.04, a_max=0.04, out=a3)\n",
    "print(a3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1, 2, 3], [4, 5, 6], [7, 8, 9]]\n"
     ]
    }
   ],
   "source": [
    "arr = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]\n",
    "\n",
    "print(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n"
     ]
    }
   ],
   "source": [
    "print(arr[1][2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [4 5 6]\n",
      " [7 8 9]]\n"
     ]
    }
   ],
   "source": [
    "arr = np.array(arr)\n",
    "print(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n"
     ]
    }
   ],
   "source": [
    "print(arr[1, 2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "10\n",
      "10\n",
      "10\n",
      "10\n",
      "10\n",
      "10\n",
      "10\n",
      "10\n",
      "10\n"
     ]
    }
   ],
   "source": [
    "class A:\n",
    "    def __init__(self, b):\n",
    "        self.b = b\n",
    "    def hehe(self, c):\n",
    "        print(c)\n",
    "\n",
    "arr = [A(i) for i in range(10)]\n",
    "for item in arr:\n",
    "\n",
    "    item.hehe(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.1 0.2 0.3 0.4]\n",
      "[[0.33 0.32]\n",
      " [0.21 0.12]]\n"
     ]
    }
   ],
   "source": [
    "a = np.array([0.1, 0.2, 0.3, 0.4])\n",
    "b = np.array([[0.33, 0.32], [0.21, 0.12]])\n",
    "print(a)\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(4,)\n",
      "(2, 2)\n"
     ]
    }
   ],
   "source": [
    "print(a.shape)\n",
    "print(b.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.1, 0.2],\n",
       "       [0.3, 0.4]])"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.reshape(b.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[False  True False ... False False False]\n"
     ]
    }
   ],
   "source": [
    "arr1 = np.random.rand(3072)\n",
    "arr2 = np.random.rand(3072)\n",
    "print((arr1 > arr2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1498\n",
      "1574\n",
      "0\n"
     ]
    }
   ],
   "source": [
    "sum1 = (arr1 > arr2).sum()\n",
    "sum2 = (arr1 < arr2).sum()\n",
    "sum3 = (arr1 == arr2).sum()\n",
    "print(sum1)\n",
    "print(sum2)\n",
    "print(sum3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1000000.0\n"
     ]
    }
   ],
   "source": [
    "a = 1e6\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.14595863987224889\n",
      "0.8931752886673391\n",
      "0.18405863683888246\n",
      "0.06690394072231665\n",
      "0.17360110230354653\n",
      "0.8110694891815146\n",
      "0.6582925438287637\n",
      "0.2424166395437075\n",
      "0.17847111545587335\n",
      "0.05377249743488466\n",
      "0.146 0.893 0.184 0.067 0.174 0.811 0.658 0.242 0.178 0.054 \n",
      "0.054 0.067 0.146 0.174 0.178 0.184 0.242 0.658 0.811 0.893 \n",
      "0.893 0.811 0.658 0.242 0.184 0.178 0.174 0.146 0.067 0.054 \n"
     ]
    }
   ],
   "source": [
    "class A:\n",
    "\n",
    "    def __init__(self, a):\n",
    "        self.a = a\n",
    "        print(a)\n",
    "\n",
    "    def __str__(self):\n",
    "        \n",
    "        return '{:.3f}'.format(self.a)\n",
    "\n",
    "import random\n",
    "\n",
    "arr = []\n",
    "\n",
    "for i in range(10):\n",
    "\n",
    "    temp = A(random.random())\n",
    "    arr.append(temp)\n",
    "\n",
    "for item in arr:\n",
    "    print(item, end=' ')\n",
    "print()\n",
    "arr.sort(key=lambda x: x.a)\n",
    "\n",
    "for item in arr:\n",
    "    print(item, end=' ')\n",
    "print()\n",
    "arr.sort(key=lambda x: x.a, reverse=True)\n",
    "\n",
    "for item in arr:\n",
    "    print(item, end=' ')\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1671756125.0\n"
     ]
    }
   ],
   "source": [
    "print(time.mktime(time.gmtime()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[-0.7026, -0.6780, -0.8171],\n",
      "        [ 0.5080,  0.1585,  1.9854],\n",
      "        [ 0.1075,  0.8763, -1.8715]])\n"
     ]
    }
   ],
   "source": [
    "import torch\n",
    "\n",
    "arr = torch.randn((3, 3))\n",
    "print(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "arr1 = torch.abs(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[0.7026, 0.6780, 0.8171],\n",
      "        [0.5080, 0.1585, 1.9854],\n",
      "        [0.1075, 0.8763, 1.8715]])\n"
     ]
    }
   ],
   "source": [
    "print(arr1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[-0.7026, -0.6780, -0.8171],\n",
      "        [ 0.5080,  0.1585,  1.9854],\n",
      "        [ 0.1075,  0.8763, -1.8715]])\n"
     ]
    }
   ],
   "source": [
    "print(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor(1.9854)\n"
     ]
    }
   ],
   "source": [
    "k = torch.max(arr)\n",
    "print(k)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor(1.9854)\n"
     ]
    }
   ],
   "source": [
    "print(torch.max(arr1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.00670738 0.3113348  0.51781943 ... 0.86351533 0.02956891 0.84962145]\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "import numpy as np\n",
    "\n",
    "arr = np.random.rand(3072)\n",
    "print(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n"
     ]
    }
   ],
   "source": [
    "arr = [i for i in range(10)]\n",
    "print(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6, 7, 8, 9]\n"
     ]
    }
   ],
   "source": [
    "print(arr[1:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.5462649]\n",
      "[0.70208212 0.58007775 0.058082   0.41782128 0.51350553 0.80035979\n",
      " 0.70935178 0.08698986 0.71747726 0.4782475 ]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "a = np.random.rand(1)\n",
    "b = np.random.rand(10)\n",
    "print(a)\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.5462649  0.70208212 0.58007775 0.058082   0.41782128 0.51350553\n",
      " 0.80035979 0.70935178 0.08698986 0.71747726 0.4782475 ]\n"
     ]
    }
   ],
   "source": [
    "c  = np.concatenate([a, b])\n",
    "print(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[-0.55337    -0.65863237 -0.41393205  0.011927    0.46671466 -0.65175927\n",
      "  0.48025272 -0.9737403  -0.47668919 -0.06320235]\n"
     ]
    }
   ],
   "source": [
    "k = -1.0 + 2 * np.random.rand(10)\n",
    "print(k)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[-0.1 -0.1 -0.1  0.1  0.1 -0.1  0.1 -0.1 -0.1 -0.1]\n"
     ]
    }
   ],
   "source": [
    "eps = 0.1\n",
    "k = eps * np.sign(k)\n",
    "print(k)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 1  1  1 -1 -1  1  1  1  0 -1]\n",
      "0\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "a = np.random.randint(low=-1, high=2, size=10)\n",
    "print(a)\n",
    "\n",
    "b = np.random.randint(low=-1, high=2)\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[[0. 0.]\n",
      "  [0. 0.]\n",
      "  [0. 0.]]\n",
      "\n",
      " [[0. 0.]\n",
      "  [0. 0.]\n",
      "  [0. 0.]]\n",
      "\n",
      " [[0. 0.]\n",
      "  [0. 0.]\n",
      "  [0. 0.]]\n",
      "\n",
      " [[0. 0.]\n",
      "  [0. 0.]\n",
      "  [0. 0.]]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "a = np.zeros((4, 3, 2))\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0. 0.]\n"
     ]
    }
   ],
   "source": [
    "print(a[1, 2])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "boundary",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.11"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "f3e11ec1aa19fe491693c05a161cdfbd0d3bc4fb713e63eb61dcdbeb91d3961d"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
